cmake_policy(SET CMP0076 NEW)

if (DEFINED ENV{FOX} AND (NOT DEFINED ENV{FOX_ROOT}))
  set(ENV{FOX_ROOT} $ENV{FOX})
endif ()
if (DEFINED ENV{FOX_ROOT})
  message(STATUS "Found FOX in $ENV{FOX_ROOT}.")
  add_definitions(-DHAS_FOX)
  include_directories("$ENV{FOX_ROOT}/include")
  link_directories("$ENV{FOX_ROOT}/lib")
  link_directories("$ENV{FOX_ROOT}/lib64")
else ()
  message(FATAL_ERROR "Cannot find FOX! Please install it and set FOX_ROOT environment variable.")
endif ()

add_library(clm)
target_link_directories(clm PUBLIC $ENV{FOX_ROOT}/lib)
target_link_libraries(clm FoX_dom FoX_sax FoX_utils FoX_wcml FoX_wkml FoX_wxml FoX_common FoX_fsys)
target_sources(clm PRIVATE
  ../../../physics/cam/shr/seq_drydep_mod.F90
  ../../../physics/cam/shr/shr_abort_mod.F90
  ../../../physics/cam/shr/shr_assert_mod.F90
  ../../../physics/cam/shr/shr_cal_mod.F90
  ../../../physics/cam/shr/shr_const_mod.F90
  ../../../physics/cam/shr/shr_expr_parser_mod.F90
  ../../../physics/cam/shr/shr_file_mod.F90
  ../../../physics/cam/shr/shr_fire_emis_mod.F90
  ../../../physics/cam/shr/shr_infnan_mod.F90
  ../../../physics/cam/shr/shr_kind_mod.F90
  ../../../physics/cam/shr/shr_log_mod.F90
  ../../../physics/cam/shr/shr_megan_mod.F90
  ../../../physics/cam/shr/shr_mpi_mod.F90
  ../../../physics/cam/shr/shr_nl_mod.F90
  ../../../physics/cam/shr/shr_orb_mod.F90
  ../../../physics/cam/shr/shr_pio_mod.F90
  ../../../physics/cam/shr/shr_spfn_mod.F90
  ../../../physics/cam/shr/shr_strconvert_mod.F90
  ../../../physics/cam/shr/shr_string_mod.F90
  ../../../physics/cam/shr/shr_sys_mod.F90
  ../../../physics/cam/shr/shr_timer_mod.F90
  ../../../physics/cam/utils/mct_mod.F90
  ../../../utils/perf_mod.F90
  biogeochem/ch4Mod.F90
  biogeochem/ch4varcon.F90
  biogeochem/CNAllocationMod.F90
  biogeochem/CNAnnualUpdateMod.F90
  biogeochem/CNBalanceCheckMod.F90
  biogeochem/CNC14DecayMod.F90
  biogeochem/CNCIsoAtmTimeSeriesReadMod.F90
  biogeochem/CNCIsoFluxMod.F90
  biogeochem/CNCStateUpdate1Mod.F90
  biogeochem/CNCStateUpdate2Mod.F90
  biogeochem/CNCStateUpdate3Mod.F90
  biogeochem/CNDriverMod.F90
  biogeochem/CNDVDriverMod.F90
  biogeochem/CNDVEstablishmentMod.F90
  biogeochem/CNDVLightMod.F90
  biogeochem/CNDVType.F90
  biogeochem/CNFireBaseMod.F90
  biogeochem/CNFireEmissionsMod.F90
  biogeochem/CNFireFactoryMod.F90
  biogeochem/CNFireLi2014Mod.F90
  biogeochem/CNFireLi2016Mod.F90
  biogeochem/CNFireLi2021Mod.F90
  biogeochem/CNFireNoFireMod.F90
  biogeochem/CNFUNMod.F90
  biogeochem/CNGapMortalityMod.F90
  biogeochem/CNGRespMod.F90
  biogeochem/CNMRespMod.F90
  biogeochem/CNNDynamicsMod.F90
  biogeochem/CNNStateUpdate1Mod.F90
  biogeochem/CNNStateUpdate2Mod.F90
  biogeochem/CNNStateUpdate3Mod.F90
  biogeochem/CNPhenologyMod.F90
  biogeochem/CNPrecisionControlMod.F90
  biogeochem/CNProductsMod.F90
  biogeochem/CNRootDynMod.F90
  biogeochem/CNSharedParamsMod.F90
  biogeochem/CNSpeciesMod.F90
  biogeochem/CNVegCarbonFluxType.F90
  biogeochem/CNVegCarbonStateType.F90
  biogeochem/CNVegComputeSeedMod.F90
  biogeochem/CNVegetationFacade.F90
  biogeochem/CNVegNitrogenFluxType.F90
  biogeochem/CNVegNitrogenStateType.F90
  biogeochem/CNVegStateType.F90
  biogeochem/CNVegStructUpdateMod.F90
  biogeochem/CropReprPoolsMod.F90
  biogeochem/CropType.F90
  biogeochem/DryDepVelocity.F90
  biogeochem/DUSTMod.F90
  biogeochem/dynCNDVMod.F90
  biogeochem/dynConsBiogeochemMod.F90
  biogeochem/FATESFireBase.F90
  biogeochem/FATESFireDataMod.F90
  biogeochem/FATESFireFactoryMod.F90
  biogeochem/FATESFireNoDataMod.F90
  biogeochem/FireEmisFactorsMod.F90
  biogeochem/MEGANFactorsMod.F90
  biogeochem/NutrientCompetitionCLM45defaultMod.F90
  biogeochem/NutrientCompetitionFactoryMod.F90
  biogeochem/NutrientCompetitionFlexibleCNMod.F90
  biogeochem/NutrientCompetitionMethodMod.F90
  biogeochem/SatellitePhenologyMod.F90
  biogeochem/SpeciesBaseType.F90
  biogeochem/SpeciesIsotopeType.F90
  biogeochem/SpeciesNonIsotopeType.F90
  biogeochem/VOCEmissionMod.F90
  biogeophys/ActiveLayerMod.F90
  biogeophys/AerosolMod.F90
  biogeophys/BalanceCheckMod.F90
  biogeophys/BareGroundFluxesMod.F90
  biogeophys/CanopyFluxesMod.F90
  biogeophys/CanopyHydrologyMod.F90
  biogeophys/CanopyStateType.F90
  biogeophys/DaylengthMod.F90
  biogeophys/EnergyFluxType.F90
  biogeophys/FrictionVelocityMod.F90
  biogeophys/GlacierSurfaceMassBalanceMod.F90
  biogeophys/HumanIndexMod.F90
  biogeophys/InfiltrationExcessRunoffMod.F90
  biogeophys/IrrigationMod.F90
  biogeophys/LakeCon.F90
  biogeophys/LakeFluxesMod.F90
  biogeophys/LakeStateType.F90
  biogeophys/LunaMod.F90
  biogeophys/OzoneBaseMod.F90
  biogeophys/OzoneFactoryMod.F90
  biogeophys/OzoneMod.F90
  biogeophys/OzoneOffMod.F90
  biogeophys/PhotosynthesisMod.F90
  biogeophys/QSatMod.F90
  biogeophys/RootBiophysMod.F90
  biogeophys/SaturatedExcessRunoffMod.F90
  biogeophys/SnowCoverFractionBaseMod.F90
  biogeophys/SnowCoverFractionFactoryMod.F90
  biogeophys/SnowCoverFractionNiuYang2007Mod.F90
  biogeophys/SnowCoverFractionSwensonLawrence2012Mod.F90
  biogeophys/SnowHydrologyMod.F90
  biogeophys/SnowSnicarMod.F90
  biogeophys/SoilHydrologyInitTimeConstMod.F90
  biogeophys/SoilHydrologyMod.F90
  biogeophys/SoilHydrologyType.F90
  biogeophys/SoilMoistStressMod.F90
  biogeophys/SoilStateInitTimeConstMod.F90
  biogeophys/SoilStateType.F90
  biogeophys/SoilWaterMovementMod.F90
  biogeophys/SoilWaterPlantSinkMod.F90
  biogeophys/SoilWaterRetentionCurveClappHornberg1978Mod.F90
  biogeophys/SoilWaterRetentionCurveFactoryMod.F90
  biogeophys/SoilWaterRetentionCurveMod.F90
  biogeophys/SoilWaterRetentionCurveVanGenuchten1980Mod.F90
  biogeophys/SolarAbsorbedType.F90
  biogeophys/SurfaceAlbedoMod.F90
  biogeophys/SurfaceAlbedoType.F90
  biogeophys/SurfaceRadiationMod.F90
  biogeophys/SurfaceResistanceMod.F90
  biogeophys/SurfaceWaterMod.F90
  biogeophys/TemperatureType.F90
  biogeophys/TotalWaterAndHeatMod.F90
  biogeophys/TridiagonalMod.F90
  biogeophys/UrbanFluxesMod.F90
  biogeophys/UrbanParamsType.F90
  biogeophys/Wateratm2lndBulkType.F90
  biogeophys/Wateratm2lndType.F90
  biogeophys/WaterBalanceType.F90
  biogeophys/WaterDiagnosticBulkType.F90
  biogeophys/WaterDiagnosticType.F90
  biogeophys/WaterFluxBulkType.F90
  biogeophys/WaterFluxType.F90
  biogeophys/WaterInfoBaseType.F90
  biogeophys/WaterInfoBulkType.F90
  biogeophys/WaterInfoIsotopeType.F90
  biogeophys/WaterInfoTracerType.F90
  biogeophys/Waterlnd2atmBulkType.F90
  biogeophys/Waterlnd2atmType.F90
  biogeophys/WaterStateBulkType.F90
  biogeophys/WaterStateType.F90
  biogeophys/WaterTracerContainerType.F90
  biogeophys/WaterTracerUtils.F90
  biogeophys/WaterType.F90
  cpl/clm_comp_shr.F90
  cpl/dshr_methods_mod.F90
  cpl/dshr_strdata_mod.F90
  cpl/dshr_stream_mod.F90
  cpl/dshr_tinterp_mod.F90
  cpl/share_esmf/ch4FInundatedStreamType.F90
  cpl/share_esmf/FireDataBaseType.F90
  cpl/share_esmf/laiStreamMod.F90
  cpl/share_esmf/ndepStreamMod.F90
  cpl/share_esmf/SoilMoistureStreamMod.F90
  cpl/share_esmf/UrbanTimeVarType.F90
  dyn_subgrid/dynColumnStateUpdaterMod.F90
  dyn_subgrid/dynColumnTemplateMod.F90
  dyn_subgrid/dynConsBiogeophysMod.F90
  dyn_subgrid/dyncropFileMod.F90
  dyn_subgrid/dynEDMod.F90
  dyn_subgrid/dynFileMod.F90
  dyn_subgrid/dynGrossUnrepMod.F90
  dyn_subgrid/dynHarvestMod.F90
  dyn_subgrid/dynInitColumnsMod.F90
  dyn_subgrid/dynlakeFileMod.F90
  dyn_subgrid/dynLandunitAreaMod.F90
  dyn_subgrid/dynPatchStateUpdaterMod.F90
  dyn_subgrid/dynpftFileMod.F90
  dyn_subgrid/dynPriorWeightsMod.F90
  dyn_subgrid/dynSubgridControlMod.F90
  dyn_subgrid/dynSubgridDriverMod.F90
  dyn_subgrid/dynTimeInfoMod.F90
  dyn_subgrid/dynurbanFileMod.F90
  dyn_subgrid/dynVarMod.F90
  dyn_subgrid/dynVarTimeUninterpMod.F90
  fates/biogeochem/DamageMainMod.F90
  fates/biogeochem/EDCanopyStructureMod.F90
  fates/biogeochem/EDCohortDynamicsMod.F90
  fates/biogeochem/EDLoggingMortalityMod.F90
  fates/biogeochem/EDMortalityFunctionsMod.F90
  fates/biogeochem/EDPatchDynamicsMod.F90
  fates/biogeochem/EDPhysiologyMod.F90
  fates/biogeochem/FatesAllometryMod.F90
  fates/biogeochem/FatesLitterMod.F90
  fates/biogeochem/FatesSoilBGCFluxMod.F90
  fates/biogeophys/EDAccumulateFluxesMod.F90
  fates/biogeophys/EDBtranMod.F90
  fates/biogeophys/EDSurfaceAlbedoMod.F90
  fates/biogeophys/FatesHydroWTFMod.F90
  fates/biogeophys/FatesPlantHydraulicsMod.F90
  fates/biogeophys/FatesPlantRespPhotosynthMod.F90
  fates/fire/SFMainMod.F90
  fates/fire/SFParamsMod.F90
  fates/main/ChecksBalancesMod.F90
  fates/main/EDInitMod.F90
  fates/main/EDMainMod.F90
  fates/main/EDParamsMod.F90
  fates/main/EDPftvarcon.F90
  fates/main/EDTypesMod.F90
  fates/main/FatesConstantsMod.F90
  fates/main/FatesGlobals.F90
  fates/main/FatesHistoryInterfaceMod.F90
  fates/main/FatesHistoryVariableType.F90
  fates/main/FatesHydraulicsMemMod.F90
  fates/main/FatesIntegratorsMod.F90
  fates/main/FatesInterfaceMod.F90
  fates/main/FatesInterfaceTypesMod.F90
  fates/main/FatesInventoryInitMod.F90
  fates/main/FatesIODimensionsMod.F90
  fates/main/FatesIOVariableKindMod.F90
  fates/main/FatesParameterDerivedMod.F90
  fates/main/FatesParametersInterface.F90
  fates/main/FatesRestartInterfaceMod.F90
  fates/main/FatesRestartVariableType.F90
  fates/main/FatesRunningMeanMod.F90
  fates/main/FatesSizeAgeTypeIndicesMod.F90
  fates/main/FatesSynchronizedParamsMod.F90
  fates/main/FatesUtilsMod.F90
  fates/parteh/PRTAllometricCarbonMod.F90
  fates/parteh/PRTAllometricCNPMod.F90
  fates/parteh/PRTGenericMod.F90
  fates/parteh/PRTLossFluxesMod.F90
  fates/parteh/PRTParametersMod.F90
  fates/parteh/PRTParamsFATESMod.F90
  init_interp/initInterp.F90
  init_interp/initInterp1dData.F90
  init_interp/initInterp2dvar.F90
  init_interp/initInterpBounds.F90
  init_interp/initInterpMindist.F90
  init_interp/initInterpMultilevelBase.F90
  init_interp/initInterpMultilevelContainer.F90
  init_interp/initInterpMultilevelCopy.F90
  init_interp/initInterpMultilevelInterp.F90
  init_interp/initInterpMultilevelSnow.F90
  init_interp/initInterpMultilevelSplit.F90
  init_interp/initInterpUtils.F90
  main/abortutils.F90
  main/accumulMod.F90
  main/atm2lndType.F90
  main/clm_initializeMod.F90
  main/clm_instMod.F90
  main/clm_varcon.F90
  main/clm_varctl.F90
  main/clm_varpar.F90
  main/clm_varsur.F90
  main/column_varcon.F90
  main/ColumnType.F90
  main/controlMod.F90
  main/decompInitMod.F90
  main/decompMod.F90
  main/filterColMod.F90
  main/filterMod.F90
  main/FireMethodType.F90
  main/FuncPedotransferMod.F90
  main/glc_elevclass_mod.F90
  main/glc2lndMod.F90
  main/glcBehaviorMod.F90
  main/GridcellType.F90
  main/histFileMod.F90
  main/init_hydrology.F90
  main/initGridCellsMod.F90
  main/initSubgridMod.F90
  main/initVerticalMod.F90
  main/landunit_varcon.F90
  main/LandunitType.F90
  main/lnd2atmMod.F90
  main/lnd2atmType.F90
  main/lnd2glcMod.F90
  main/ncdio_pio.F90
  main/ncdio_utils.F90
  main/organicFileMod.F90
  main/paramUtilMod.F90
  main/PatchType.F90
  main/pftconMod.F90
  main/readParamsMod.F90
  main/restFileMod.F90
  main/reweightMod.F90
  main/subgridAveMod.F90
  main/subgridMod.F90
  main/subgridRestMod.F90
  main/subgridWeightsMod.F90
  main/surfrdMod.F90
  main/surfrdUtilsMod.F90
  main/TopoMod.F90
  soilbiogeochem/SoilBiogeochemCarbonFluxType.F90
  soilbiogeochem/SoilBiogeochemCarbonStateType.F90
  soilbiogeochem/SoilBiogeochemCompetitionMod.F90
  soilbiogeochem/SoilBiogeochemDecompCascadeBGCMod.F90
  soilbiogeochem/SoilBiogeochemDecompCascadeConType.F90
  soilbiogeochem/SoilBiogeochemDecompCascadeMIMICSMod.F90
  soilbiogeochem/SoilBiogeochemDecompMod.F90
  soilbiogeochem/SoilBiogeochemLittVertTranspMod.F90
  soilbiogeochem/SoilBiogeochemNitrifDenitrifMod.F90
  soilbiogeochem/SoilBiogeochemNitrogenFluxType.F90
  soilbiogeochem/SoilBiogeochemNitrogenStateType.F90
  soilbiogeochem/SoilBiogeochemNitrogenUptakeMod.F90
  soilbiogeochem/SoilBiogeochemNLeachingMod.F90
  soilbiogeochem/SoilBiogeochemNStateUpdate1Mod.F90
  soilbiogeochem/SoilBiogeochemPotentialMod.F90
  soilbiogeochem/SoilBiogeochemPrecisionControlMod.F90
  soilbiogeochem/SoilBiogeochemStateType.F90
  soilbiogeochem/SoilBiogeochemVerticalProfileMod.F90
  utils/AnnualFluxDribbler.F90
  utils/array_utils.F90
  utils/clm_nlUtilsMod.F90
  utils/clm_time_manager.F90
  utils/clm_varorb.F90
  utils/clmfates_interfaceMod.F90
  utils/clmfates_interfaceMod.F90
  utils/clmfates_interfaceMod.F90
  utils/clmfates_paraminterfaceMod.F90
  utils/domainMod.F90
  utils/fileutils.F90
  utils/getdatetime.F90
  utils/IssueFixedMetadataHandler.F90
  utils/NumericsMod.F90
  utils/quadraticMod.F90
  utils/restUtilMod.F90
  utils/SimpleMathMod.F90
  utils/SparseMatrixMultiplyMod.F90
  utils/spmdMod.F90
)
